﻿using MediatR;
using T.Settlement.Domain;
using T.Settlement.Read.API.Application.Command.InvoiceCommand;
using T.Settlement.Repository.SettlementInterface;

namespace T.Settlement.Read.API.Application.CommandHandlers.InvoiceHandler
{
    public class InvoiceBackfillCommandHandler : IRequestHandler<InvoiceBackfillCommand, Invoice>
    {
        private readonly IInvoiceSRepository _invoiceSRepository;
        /// <summary>
        /// 构造函数注入
        /// </summary>
        /// <param name="invoiceSRepository"></param>
        public InvoiceBackfillCommandHandler(IInvoiceSRepository invoiceSRepository)
        {
            _invoiceSRepository = invoiceSRepository;
        }
        public async Task<Invoice> Handle(InvoiceBackfillCommand request, CancellationToken cancellationToken)
        {
            return (await _invoiceSRepository.GetAllAsync()).Where(x => x.InvoiceId == request.InvoiceId).FirstOrDefault();
        }
    }
}
